from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-17 14:02:31.599010
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 17, May, 2022
Time: 14:02:39
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.3136
Nobs: 659.000 HQIC: -49.6892
Log likelihood: 8125.19 FPE: 2.07508e-22
AIC: -49.9269 Det(Omega_mle): 1.81204e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.316526 0.060736 5.211 0.000
L1.Burgenland 0.105557 0.038896 2.714 0.007
L1.Kärnten -0.109408 0.020391 -5.366 0.000
L1.Niederösterreich 0.199594 0.080993 2.464 0.014
L1.Oberösterreich 0.121780 0.080100 1.520 0.128
L1.Salzburg 0.256940 0.041321 6.218 0.000
L1.Steiermark 0.043051 0.054196 0.794 0.427
L1.Tirol 0.101011 0.043675 2.313 0.021
L1.Vorarlberg -0.063044 0.038703 -1.629 0.103
L1.Wien 0.033288 0.070788 0.470 0.638
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.047095 0.129535 0.364 0.716
L1.Burgenland -0.032061 0.082954 -0.386 0.699
L1.Kärnten 0.040703 0.043489 0.936 0.349
L1.Niederösterreich -0.183608 0.172736 -1.063 0.288
L1.Oberösterreich 0.448451 0.170833 2.625 0.009
L1.Salzburg 0.284654 0.088127 3.230 0.001
L1.Steiermark 0.107045 0.115586 0.926 0.354
L1.Tirol 0.310868 0.093148 3.337 0.001
L1.Vorarlberg 0.022163 0.082543 0.269 0.788
L1.Wien -0.037307 0.150973 -0.247 0.805
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184754 0.031198 5.922 0.000
L1.Burgenland 0.089955 0.019979 4.502 0.000
L1.Kärnten -0.007610 0.010474 -0.727 0.467
L1.Niederösterreich 0.256783 0.041603 6.172 0.000
L1.Oberösterreich 0.155213 0.041144 3.772 0.000
L1.Salzburg 0.042415 0.021225 1.998 0.046
L1.Steiermark 0.023600 0.027838 0.848 0.397
L1.Tirol 0.084131 0.022434 3.750 0.000
L1.Vorarlberg 0.053542 0.019880 2.693 0.007
L1.Wien 0.118297 0.036361 3.253 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110496 0.031251 3.536 0.000
L1.Burgenland 0.045972 0.020013 2.297 0.022
L1.Kärnten -0.014027 0.010492 -1.337 0.181
L1.Niederösterreich 0.183666 0.041674 4.407 0.000
L1.Oberösterreich 0.327781 0.041214 7.953 0.000
L1.Salzburg 0.101518 0.021261 4.775 0.000
L1.Steiermark 0.109550 0.027886 3.929 0.000
L1.Tirol 0.096064 0.022473 4.275 0.000
L1.Vorarlberg 0.059831 0.019914 3.004 0.003
L1.Wien -0.021774 0.036423 -0.598 0.550
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111395 0.058171 1.915 0.055
L1.Burgenland -0.043522 0.037252 -1.168 0.243
L1.Kärnten -0.046206 0.019530 -2.366 0.018
L1.Niederösterreich 0.143645 0.077571 1.852 0.064
L1.Oberösterreich 0.159892 0.076717 2.084 0.037
L1.Salzburg 0.281992 0.039575 7.125 0.000
L1.Steiermark 0.054951 0.051907 1.059 0.290
L1.Tirol 0.164976 0.041830 3.944 0.000
L1.Vorarlberg 0.095990 0.037068 2.590 0.010
L1.Wien 0.078961 0.067798 1.165 0.244
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062768 0.045882 1.368 0.171
L1.Burgenland 0.031093 0.029383 1.058 0.290
L1.Kärnten 0.051367 0.015404 3.335 0.001
L1.Niederösterreich 0.206136 0.061184 3.369 0.001
L1.Oberösterreich 0.317313 0.060510 5.244 0.000
L1.Salzburg 0.041301 0.031215 1.323 0.186
L1.Steiermark 0.006765 0.040941 0.165 0.869
L1.Tirol 0.131493 0.032994 3.985 0.000
L1.Vorarlberg 0.065857 0.029237 2.253 0.024
L1.Wien 0.086833 0.053475 1.624 0.104
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171084 0.055082 3.106 0.002
L1.Burgenland 0.005175 0.035275 0.147 0.883
L1.Kärnten -0.065131 0.018493 -3.522 0.000
L1.Niederösterreich -0.095552 0.073453 -1.301 0.193
L1.Oberösterreich 0.203459 0.072644 2.801 0.005
L1.Salzburg 0.054030 0.037474 1.442 0.149
L1.Steiermark 0.241097 0.049151 4.905 0.000
L1.Tirol 0.500547 0.039610 12.637 0.000
L1.Vorarlberg 0.058611 0.035100 1.670 0.095
L1.Wien -0.070886 0.064198 -1.104 0.270
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.149667 0.061040 2.452 0.014
L1.Burgenland 0.004165 0.039090 0.107 0.915
L1.Kärnten 0.060222 0.020493 2.939 0.003
L1.Niederösterreich 0.180295 0.081397 2.215 0.027
L1.Oberösterreich -0.055519 0.080500 -0.690 0.490
L1.Salzburg 0.206038 0.041527 4.961 0.000
L1.Steiermark 0.134087 0.054467 2.462 0.014
L1.Tirol 0.069403 0.043894 1.581 0.114
L1.Vorarlberg 0.143680 0.038896 3.694 0.000
L1.Wien 0.109807 0.071142 1.544 0.123
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.373895 0.036027 10.378 0.000
L1.Burgenland -0.000242 0.023071 -0.010 0.992
L1.Kärnten -0.021635 0.012095 -1.789 0.074
L1.Niederösterreich 0.216924 0.048042 4.515 0.000
L1.Oberösterreich 0.228148 0.047513 4.802 0.000
L1.Salzburg 0.038819 0.024510 1.584 0.113
L1.Steiermark -0.016067 0.032147 -0.500 0.617
L1.Tirol 0.093313 0.025907 3.602 0.000
L1.Vorarlberg 0.054059 0.022957 2.355 0.019
L1.Wien 0.034569 0.041989 0.823 0.410
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037023 0.118337 0.174203 0.143881 0.099478 0.086215 0.039385 0.211951
Kärnten 0.037023 1.000000 -0.019119 0.135047 0.052657 0.089921 0.440561 -0.060488 0.094027
Niederösterreich 0.118337 -0.019119 1.000000 0.324911 0.129949 0.283587 0.075443 0.161694 0.299769
Oberösterreich 0.174203 0.135047 0.324911 1.000000 0.221257 0.308922 0.168234 0.150451 0.251963
Salzburg 0.143881 0.052657 0.129949 0.221257 1.000000 0.129120 0.099320 0.114945 0.130725
Steiermark 0.099478 0.089921 0.283587 0.308922 0.129120 1.000000 0.137618 0.118310 0.050757
Tirol 0.086215 0.440561 0.075443 0.168234 0.099320 0.137618 1.000000 0.069458 0.147697
Vorarlberg 0.039385 -0.060488 0.161694 0.150451 0.114945 0.118310 0.069458 1.000000 0.007475
Wien 0.211951 0.094027 0.299769 0.251963 0.130725 0.050757 0.147697 0.007475 1.000000